package cn.webrx;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Reg9 {
    public static void main(String[] args) {
        while(true){
            String t = genStr();
            if(isOk(t)) {
                System.out.printf("%s = 100%n", t);
                break;
            }
        }
    }

    public static String genStr(){
        Random rand = new Random();
        StringBuilder sbu = new StringBuilder("1");
        String[] op = new String[]{"","+","-"};
        for(int i=2;i<=9;i++){
            sbu.append(String.format("%s%d",op[rand.nextInt(op.length)],i));
        }
        return sbu.toString();
    }

    public static boolean isOk(String str) {
        Pattern pattern = Pattern.compile("-?\\d+");
        Matcher m = pattern.matcher(str);
        int sum = 0;
        while (m.find()) {
            int t = Integer.parseInt(m.group());
            sum += t;
        }
        return sum == 100 ? true : false;
    }
}
